package com.xmkj.bearuser;

import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.View;
import android.widget.FrameLayout;

import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.widget.tablayout.BottomTabLayout;
import com.common.widget.tablayout.CustomTabEntity;
import com.common.widget.tablayout.OnTabSelectListener;
import com.common.widget.tablayout.TabEntity;
import com.xmkj.bearuser.deal.DealFragment;
import com.xmkj.bearuser.home.HomeFragment;
import com.xmkj.bearuser.jifen.JiFenFragment;
import com.xmkj.bearuser.my.MyFragment;
import com.xmkj.bearuser.toutiao.TouTiaoFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Create by leo
 * 创建日期：2018/5/3
 * 描述：
 */

public class MainWinActivity extends BaseMvpActivity {
    @BindView(R.id.fragment)
    FrameLayout fragment;
    @BindView(R.id.tab_layout)
    BottomTabLayout tabLayout;
    private String[] mTitles;
    private ArrayList<Fragment> fragments;
    //模块未选中图片
    private int[] mIconUnSelectIds = {};
    //模块选中图片
    private int[] mIconSelectIds = {};
    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main_win;
    }

    @Override
    protected void onViewCreated() {

    }

    @Override
    protected void doLogicFunc() {
        mTitles = new String[]{"首页", "积分商城", "最新成交", "头条文章","我的"};
        initTabLayout();
    }

    @Override
    protected void setStatusBar() {
//        StatusBarUtil.setStatusBarColor(this, R.color.black);
    }

    @Override
    protected void setNavigation() {
        super.setNavigation();m_statusBar.setVisibility(View.GONE);

    }

    /**
     * 按两次返回键退出
     */
    private long exitTime = 0;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {

            if ((System.currentTimeMillis() - exitTime) > 2000) {
                showToastMsg("再按一次退出" + getString(R.string.app_name));
                exitTime = System.currentTimeMillis();
                return true;
            } else {
                onBackPressed();
            }
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void bindKnife() {
        ButterKnife.bind(this);
    }

    private void initTabLayout() {
        for (int i = 0; i < mTitles.length; i++) {
            mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconUnSelectIds[i]));
        }

        fragments = new ArrayList<>();
        fragments.add(new HomeFragment());
        fragments.add(new JiFenFragment());
        fragments.add(new DealFragment());
        fragments.add(new TouTiaoFragment());
        fragments.add(new MyFragment());
        tabLayout.setTabData(mTabEntities, this, R.id.fragment, fragments);
        tabLayout.onRestoreInstanceState(savedInstanceState);

        tabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
            }

            @Override
            public void onTabReselect(int position) {
            }
        });
    }
}
